package com.atwisdom.star.controller;

import com.atwisdom.star.common.vo.ResultInfo;
import com.atwisdom.star.core.bsl.functionClass.impl.FileManageServiceImpl;
import com.atwisdom.star.exception.pojo.BusinessException;
import com.atwisdom.star.log.aop.StarAnnotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
@RequestMapping("/file")
public class FileController {
    private FileManageServiceImpl fileManageService;
    @Autowired
    public void setFileManageService(FileManageServiceImpl fileManageService) {
        this.fileManageService = fileManageService;
    }

    /**
     *
     * @param files 接收参数据
     * @return 返回结果
     * @throws BusinessException  异常
     */
    @StarAnnotation
    @PostMapping(value = "/uploadFiles")
    public ResultInfo<?> uploadFiles(@RequestParam MultipartFile[] files) throws BusinessException {
        return this.fileManageService.uploadFiles(files);
    }

    /**
     *
     * @param file 接收参数据
     * @return 返回结果
     * @throws BusinessException  异常
     */
    @StarAnnotation
    @PostMapping(value = "/uploadFile")
    public ResultInfo<?> uploadFile(@RequestParam("file") MultipartFile file) throws BusinessException {
        return this.fileManageService.uploadFile(file);
    }

    /**
     *
     * @param param 接收参数据
     * @throws BusinessException  异常
     */
    @StarAnnotation
    @PostMapping(value = "/downloadFile")
    public void downloadFile(@RequestBody Map<String,String> param , HttpServletResponse response, HttpServletRequest request) throws BusinessException {
        this.fileManageService.downloadFile(param,response,request);
    }

    /**
     *
     * @param param 接收参数据
     * @throws BusinessException  异常
     */
    @StarAnnotation
    @PostMapping(value = "/downloadFileBase64")
    public void downloadFileBase64(@RequestBody Map<String,String> param ) throws BusinessException {
        this.fileManageService.downloadFileBase64(param);
    }


    /**
     *
     * @param param 接收参数据
     * @return 返回结果
     * @throws BusinessException  异常
     */
    @StarAnnotation
    @PostMapping(value = "/deleteFile")
    public ResultInfo<?> deleteFile(@RequestBody Map<String,String> param) throws BusinessException {
        return this.fileManageService.deleteFile(param);
    }
}
